<?php require 'common/head.php'; ?>
<?php
    require '../db_connection.php';

    if ($_GET['status'] && $_GET['id']) {
      $id = $_GET['id'];
      $sql = "UPDATE volunteers SET status={$_GET['status']} WHERE id=$id";
      if ($conn->query($sql) === TRUE) {
          echo "<script>alert('更新成功');location.href='volunteer_list.php';</script>";
      } else {
          echo "<script>alert('更新失败');history.back();</script>";
      }
      $conn->close();
      exit;
    }

    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        $id       = $_POST['id'];
        $name     = $_POST['name'];
        $email    = $_POST['email'];

        $sql = "UPDATE volunteers SET name='$name', email='$email' WHERE id=$id";
        if ($conn->query($sql) === TRUE) {
            echo "<script>alert('更新成功');location.href='volunteer_list.php';</script>";
        } else {
            echo "<script>alert('更新失败');history.back();</script>";
        }
        $conn->close();
        die();
    }

    $id   = $_GET['id'];
    $sql    = "SELECT * FROM user WHERE id=$id";
    $result = $conn->query($sql);
    $info   = $result->fetch_assoc();

    $result->free();
    $conn->close();
?>
</head>
<body>
<div class="panel admin-panel">
  <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>编辑用户-<?php echo $info['username']; ?></strong></div>
  <div class="body-content">
  <form method="post" class="form-x" action="user_edit.php" style="margin-top:20px;" enctype="multipart/form-data">  
      <div class="form-group">
        <div class="label">
          <label>用户名</label>
        </div>
        <div class="field">
          <input type="text" class="input " value="<?php echo $info['username']; ?>" name="username" data-validate="required:请输入用户名" />
          <input type="hidden" value="<?php echo $info['id']; ?>" name="id" />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>姓名</label>
        </div>
        <div class="field">
          <input type="text" class="input " value="<?php echo $info['true_name']; ?>" name="true_name" data-validate="required:请输入名字" />
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>密码</label>
        </div>
        <div class="field">
          <input type="password" class="input " value="" name="password" />
        </div>
      </div>
      <div class="form-group" style="display:flex;align-items:center;">
        <div class="label">
          <label>性别</label>
        </div>
        <div class="field">
            <label>男 <input type="radio" value="1" name="sex" <?php if ($info['sex'] == 1) echo 'checked'; ?>/></label>
            <label>女 <input type="radio" value="2" name="sex" <?php if ($info['sex'] == 2) echo 'checked'; ?>/></label>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>手机号</label>
        </div>
        <div class="field">
          <input type="text" class="input " value="<?php echo $info['phone']; ?>" name="phone"/>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>邮箱</label>
        </div>
        <div class="field">
          <input type="text" class="input " value="<?php echo $info['email']; ?>" name="email"/>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>年龄</label>
        </div>
        <div class="field">
          <input type="text" class="input " value="<?php echo $info['age']; ?>" name="age"/>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>地址</label>
        </div>
        <div class="field">
          <textarea class="input" name="address" style="height:90px;"><?php echo $info['address']; ?></textarea>
        </div>
      </div> 
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main" type="submit"> 提交</button>
          <!-- <button class="button bg-main" type="reset">清除</button> -->
        </div>
      </div>    
    </form>
  </div>
</div>

</body></html>   